<template>
	<!-- <view>用户反馈</view> -->
	<view class="zong">
		<view class="con">
			<input class="uni-input" confirm-type="search" v-model="feedbackContent" placeholder="请输入您需要反馈得内容" />
		</view>
		<view class="touxiangicon"   @click="uploadImg">
			<image  class="huiyuan_img" :src="feedbackFile" v-model="feedbackFile"></image>
		</view>
		<view class="queding">
			<button class="save" @click="save">保存</button>
		</view>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				feedbackFile: "",
				feedbackContent: '',
			}
		},
		mounted() {
			
		},
		methods: {
			uploadImg(){
			    uni.chooseImage({
			        count: 1, //默认9
			        sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
			        sourceType: ['album'], //从相册选择
			        success:res => {
			            this.feedbackFile = res.tempFilePaths[0]
			            //上传给后台
			            uni.uploadFile({
			                url:'http://localhost:7000/bbs/bbs/updateFile',
			                filePath: res.tempFilePaths[0],
							name: 'file',
			                success: (uploadFileRes) => {
								// this.feedbackFile = uploadFileRes.data.data
								this.datas = uploadFileRes.data.split(",")
								let msg = this.datas[1].split("\"")[3]
								let badMsg = this.datas[1].split("\"")[4]
								let status = this.datas[2].split("\"")[3]
								if ( status == 200 ){
									this.feedbackFile = this.datas[0].split("\"")[3]
									uni.showToast({
										title: msg,
										duration: 2000
									});
								}else{
									uni.showToast({
										title: badMsg,
										duration: 2000
									});
								}
								
			                }
			            })
			        }	
			    });
			},
			save(){
				uni.request({
				    url: `http://localhost:7000/customer/customer/userFeedback/`, //接口地址。
				    data: {
						userId: 99,
						userName: '叁叁' ,
				        feedbackContent: this.feedbackContent ,
						feedbackFile: this.feedbackFile ,
				    },
					method:'POST',
				    success: (res) => {
				        console.log(res)
						this.feedbackContent = '' 
						this.feedbackFile = '' 
				    }
				});
			},
		},
	}
	
</script>

<style lang="scss">
</style>
